#include"DXDevice.h"
DXDevice::DXDevice(HWND hwnd)
{
	
	Create_Direct9();
	Create_D3D_Para(hwnd);
	Create_Device(hwnd);
}
DXDevice::DXDevice()
{
}
DXDevice::~DXDevice()
{
}
bool DXDevice::Create_Direct9()
{
	d3d=Direct3DCreate9(D3D_SDK_VERSION);
	return true;
}
bool DXDevice::Create_D3D_Para(HWND hwnd)
{
	ZeroMemory(&dpp,sizeof(dpp));
	dpp.Windowed=TRUE;
	dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
	dpp.BackBufferFormat=D3DFMT_X8R8G8B8;
	dpp.BackBufferCount=1;
	dpp.BackBufferWidth=800;
	dpp.BackBufferHeight=600;
	dpp.hDeviceWindow=hwnd;
	return true;
}
bool DXDevice::Create_Device(HWND hwnd)
{
	if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&dpp,&d3ddev)))
	{
		if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&dpp,&d3ddev)))
		{
			if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&dpp,&d3ddev)))
			{
				return false;
			}
		}
	}
}
LPDIRECT3DDEVICE9 DXDevice::Get_Device()
{
	return d3ddev;
}
LPDIRECT3D9 DXDevice::Get_d3d()
{
	return d3d;
}